Tryit Editor v2.3

Edit This Code:
<!DOCTYPE html> <html> <body> Select your favorite car: <br> <select id="mySelect" size="4"> <option label="Volvo">Volvo (Latin for "I roll")</option> <option label="Saab">Saab (Swedish Aeroplane AB)</option> <option label="Mercedes">Mercedes (Mercedes-Benz)</option> <option label="Audi">Audi (Auto Union Deutschland Ingolstadt)</option> </select> <p>Click the button to return the label value of the selected car.</p> <button type="button" onclick="myFunction()">Try it</button> <script> function myFunction() { var x = document.getElementById("mySelect").selectedIndex; alert(document.getElementsByTagName("option")[x].label); } </script> </body> <!-- Mirrored from www.w3schools.com/jsref/tryit.asp?filename=tryjsref_option_label2 by HTTrack Website Copier/3.x [XR&CO'2014], Fri, 23 Jan 2015 08:34:45 GMT --> </html>
Result:
Try it Yourself - © w3schools.com